package servidor;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.ArrayList;
import java.util.StringTokenizer;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

import cliente.VentanaPrincipal;
import excepciones.ConfirmarAccionException;

public class VentanaModificarUltimaAccion extends JFrame {

	private JPanel contentPane;
	private JFrame estaVentana;
	private ButtonGroup bg;
	private ArrayList<JRadioButton> listabotones= new ArrayList<JRadioButton>();
	


	/**
	 * Create the frame.
	 */
	public VentanaModificarUltimaAccion(final String variable, final String placa) {
		estaVentana = this;
		setBounds(100, 100, 450, 250);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JButton btnConfirmar = new JButton("Confirmar");
		btnConfirmar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				//Realizar el envio al servidor y aceptación

				
				int i;
				for(i=0; i<listabotones.size();i++)
				{
					if(listabotones.get(i).isSelected())
					{
						String eleccion=listabotones.get(i).getText();
						VentanaServidor.panelVariables.bDPlacas.cambiarUltimaAccion(placa, variable, eleccion);
						//Hay que actualizar la lista
						VentanaServidor.panelVariables.modificarAccion(eleccion);
						dispose();
						break;
						
					}
				}
				
				
				
			}
		});
		btnConfirmar.setFont(new Font("Times New Roman", Font.BOLD, 14));
		btnConfirmar.setBounds(103, 188, 110, 30);
		contentPane.add(btnConfirmar);
		
		JButton btnRechazar = new JButton("Rechazar");
		btnRechazar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				dispose();
			}
		});
		btnRechazar.setFont(new Font("Times New Roman", Font.BOLD, 14));
		btnRechazar.setBounds(245, 188, 100, 30);
		contentPane.add(btnRechazar);
		
		JLabel lblAccion = new JLabel("");
		lblAccion.setFont(new Font("Times New Roman", Font.BOLD, 14));
		lblAccion.setBounds(80, 92, 120, 30);
		contentPane.add(lblAccion);
		
		ArrayList<String> lineastemp = VentanaServidor.panelVariables.bDPlacas.obtenerAccionesParaVariable(variable);
		bg= new ButtonGroup();
		for(int i=0; i<lineastemp.size() && !(lineastemp.get(i).equals("202 FINACCIONES"));i++)
		{
			JRadioButton rdbtnNewRadioButton1 = new JRadioButton(lineastemp.get(i));
			rdbtnNewRadioButton1.setBounds(75, 70+(25*i), 300, 30);
			bg.add(rdbtnNewRadioButton1);
			listabotones.add(rdbtnNewRadioButton1);
			contentPane.add(rdbtnNewRadioButton1);		
		}
		
		setUndecorated(true);
		setLocationRelativeTo(null);
		setVisible(true);
		setResizable(false);
		setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		
		
	}

}
